<template>
	<div>
		<div class="activitiesTwoPro" v-if="dataList.length>0">
			<div class="proul" v-if="productdata.length>0">
				<active-item 
					:buttonActive="TwoproductStyle == 'E' ?  null : buttonActive.bind(this,val)" 
					:itemType="TwoproductStyle" v-for="(val, index) in productdata" 
					:key="'activitiesTwoPro' + index" 
					:detail="val">
				</active-item>
				<div v-if="productdata.length==0 && env === 'edit'" style="height: 2.5rem;line-height: 2.5rem;">暂无数据</div>
				<div style="clear: both;"></div>
			</div>
		</div>
		<div v-if="dataList.length==0 && env === 'edit'" style="height: 2.5rem;line-height: 2.5rem;">请配置商品数据</div>
	</div>
</template>

<script>
	import { getPageNameOrVirtualPageName } from "../../utils/getPageName";
	import { queryGoodsList } from '@/utils/ReturnAxios'
	import ActiveItem from '../ActiveItem'
	export default {
		props: {
			dataList: {
				type: Array,
				default: () => []
			},
			config: {
				type: Object,
				default: () => {}
			},
			part:{
				type:Number,
				default:1
			}
		},
		data() {
			return {
				codeList: [],
				productdata: [],
				isOnLoad: true,
			}
		},
		components: {
			ActiveItem
		},
		methods: {
			goodsCodearrey() {
				this.codeList = []
				this.productdata = []
				if(this.dataList.length == 0) {
					return
				}
				if(this.dataList && this.dataList.length > 0) {
					for(var i = 0; i < this.dataList.length; i++) {
						this.productdata.push(this.dataList[i].goodsNewVO)
					}
					this.getdetaildata()
				}
			},
			async queryDetail() {
				this.isOnLoad = true
				var goodscodeList = this.codeList
				if(goodscodeList.length == 0) {
					return
				}
				var config = {
					goodscodeList: goodscodeList
				}
				var res = await queryGoodsList(config)
				res = res.data
				this.productdata = res.data[0]
				this.isOnLoad = false
				this.getdetaildata()
				if(!res.returnCode) {
					return
				}
			},
			getdetaildata() {
				for(var i = 0; i < this.dataList.length; i++) {
					for(var j = 0; j < this.productdata.length; j++) {
						if(this.dataList[i].goodsCode == this.productdata[j].goodsCode) {
							this.productdata[j].mainPic = this.dataList[i].publicityPicture
							this.productdata[j].regularTypeLabel = this.dataList[i].relTitle
						}
					}
				}
			},
			buttonActive(val) {
				this.$router.push({
					path: 'detail?code=' + val.goodsCode
				})
			}
		},
		computed: {
			pageName() {
				return getPageNameOrVirtualPageName();
			},
			TwoproductStyle() {
				if(this.config.id) {
					if(parseInt(this.getCurrentVDONew(this.config.id, this.part).config.TwoproductStyle) == 0) {
						return 'E';
					} else if(parseInt(this.getCurrentVDONew(this.config.id, this.part).config.TwoproductStyle) == 1) {
						return 'H';
					} else if(parseInt(this.getCurrentVDONew(this.config.id, this.part).config.TwoproductStyle) == 2) {
						return 'I';
					}

				}
			},
			env() {
				return window.environment; // 获取是否是编辑状态
			},
		},

		watch: {
			dataList() {
				this.goodsCodearrey()
			},
		},
		mounted() {
			this.goodsCodearrey()
		},
	}
</script>

<style>
	.activitiesTwoPro .proul {
		padding: 0.75rem;
		position: relative;
	}
</style>